//用户中心
import React from 'react'
import PureRenderMixin from 'react-addons-pure-render-mixin';

import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { hashHistory } from 'react-router'

import Header from '../../components/Header/index.jsx';
import UserInfo from '../../components/userInfo/index.jsx';
import OrderList from './subpage/OrderList.jsx';
class User extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
    }
    render() {
        let {userinfo} = this.props
        return (
            <div>
                <Header
                    {...{
                        title:'用户中心',
                        backRouter:'/'
                    }}
                />
                <UserInfo 
                    {...{
                        username:userinfo.username,
                        city:userinfo.cityName 
                    }}
                />
                <OrderList
                    {...{
                        username:userinfo.username
                    }}
                />
            </div>
        )
    }
    componentDidMount() {
        //验证是否登录了(未登录跳转到登录页面)
        if(!this.props.userinfo.username){
            hashHistory.push('/Login')
        }
    }
}

//-------------------redux react 绑定--------------------
function mapStateToProps(state) {
    return {
        userinfo: state.userinfo
    }
}
function mapDispatchToProps(dispatch) {
    return {
    }
}
export default connect(
    mapStateToProps,
    mapDispatchToProps
)(User)    